* Engel for CPI:
use processed/cpisave/cpi_master.dta,clear
drop if I ==.
drop if I < 0
keep if I > 0
qui forvalues x = 1/85	 {
keep if b`x' <1 
keep if b`x' > -0.00001 
}
 
gen logI = log(I)
qui forvalues x = 1/85	 {
	lowess b`x' logI  if datayear ==2001, generate(tmp) nograph
	gen b`x'_hat = tmp
	drop tmp
}

qui forvalues t = 2002/2017 {

qui forvalues x = 1/85 {
	lowess b`x' logI  if datayear == `t', generate(tmp) nograph
	replace b`x'_hat = tmp if datayear == `t'
	drop tmp
} 
}

keep datayear I *_hat weight caseno
duplicates drop caseno datayear,force
drop caseno

outsheet using DataforMatlab\UK_Budget_CPI.csv, comma replace nonames

* comparison *

use processed/RPImicro,clear
keep if datayear >2000
forvalues x = 1/17	 {
gen b`x' = s_RPI_`x'
drop if b`x' ==.
}
drop if I ==.
drop if I < 0

keep if I > 0
qui forvalues x = 1/17	 {
keep if b`x' <1 
keep if b`x' > -0.00001 
}

gen logI = log(I)
qui forvalues x = 1/17	 {
	lowess b`x' logI  if datayear ==2001, generate(tmp) nograph
	gen b`x'_hat = tmp
	drop tmp
}

qui forvalues t = 2002/2017 {

qui forvalues x = 1/17 {
	lowess b`x' logI  if datayear == `t', generate(tmp) nograph
	replace b`x'_hat = tmp if datayear == `t'
	drop tmp
} 
}

keep datayear I b1_hat b2_hat b3_hat b4_hat b5_hat b6_hat b7_hat b8_hat b9_hat b10_hat b11_hat b12_hat b13_hat b14_hat b15_hat b16_hat b17_hat weight caseno
duplicates drop caseno datayear,force
drop caseno

outsheet using DataforMatlab\UK_Budget_S.csv, comma replace nonames



